<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <link rel="stylesheet" type="text/css" href="../../script/libs/sort/style.css">
    <style type="text/css">
        body {
            background: rgba(244, 244, 244, 1);
        }

        .search--active,
        .search--unactive {
            padding: 10px 15px;
            background: rgba(90, 194, 255, 1);
        }

        .search {
            height: 30px;
            background: rgba(255, 255, 255, 0.26);
            border-radius: 20px;
        }

        .search-icon {
            width: 17px;
            height: 16px;
            margin-right: 5px;
            margin-left: 10px;
        }

        .search-text {
            font-size: 14px;
            font-weight: 500;
            color: rgba(255, 255, 255, 1);
        }

        .cancel {
            font-size: 15px;
            font-weight: 500;
            color: rgba(255, 255, 255, 1);
            margin-left: 15px;
        }

        .form-text {
            font-size: 14px;
            font-weight: 500;
            color: rgba(255, 255, 255, 1);
        }

        .form-text::placeholder {
            font-size: 14px;
            font-weight: 500;
            color: rgba(255, 255, 255, 1);
        }

        span {
            width: fit-content;
            height: fit-content;
            min-width: fit-content;
            min-height: fit-content;
        }

        .member-type {
            height: 42px;
            padding: 17px 0 0 15px;
            font-size: 12px;
            font-weight: 400;
            color: rgba(128, 128, 128, 1);
        }

        .member-item {
            height: 50px;
            background: rgba(255, 255, 255, 1);
        }

        .member-item-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            overflow: hidden;
            margin: 0 15px;
        }

        .member-item-name {
            font-size: 15px;
            font-weight: 400;
            color: rgba(25, 25, 25, 1);
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div class="search--unactive" v-show="!searchActive" @click="searchActive = !searchActive">
            <div class="search" data-flex="main:center cross:center">
                <div class="search-icon">
                    <img src="../../image/ui/search.png" alt="">
                </div>
                <div class="search-text">搜索</div>
            </div>
        </div>
        <div class="search--active" v-show="searchActive" data-flex="cross:center">
            <div class="search" data-flex-box="1" data-flex="cross:center">
                <div class="search-icon">
                    <img src="../../image/ui/search.png" alt="">
                </div>
                <input class="form-text" id="search-input" data-flex="cross:center" v-model="keyword" data-flex-box="1" type="text" placeholder="搜索">
            </div>
            <div class="cancel" @click="searchActive = !searchActive;keyword = ''">
                取消
            </div>
        </div>
        <div class="initials">
            <ul></ul>
        </div>
        <div v-show="pageParam.teacherName.indexOf(keyword) !== -1">
            <div class="member-type">
                <span>班主任</span>
            </div>
            <div class="member-item" data-flex="cross:center">
                <div class="member-item-avatar">
                    <img :src="pageParam.teacherIcon" width="100%" height="100%" alt="">
                </div>
                <div class="member-item-name">
                    <span>{{ pageParam.teacherName }}</span>
                </div>
            </div>
        </div>
        <div v-for="item,index in chartList" v-if="resultData[item] && resultData[item].length">
            <div class="member-type">
                <span :id="item == '未分组' ? 'default' : item">{{item}}</span>
            </div>
            <div class="member-item" v-for="student in resultData[item]" data-flex="cross:center"
                @click="handleItem(student)">
                <div class="member-item-avatar">
                    <img :src="student.icon" width="100%" height="100%" alt="">
                </div>
                <div class="member-item-name">
                    <span>{{ student.name }}</span>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript" src="../../script/libs/sort/jquery.charfirst.pinyin.js"></script>
<script type="text/javascript" src="../../script/libs/sort/sort.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm, pageParam;
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        pageParam = api.pageParam;
        api.addEventListener({
            name: 'deleteStudent'
        }, function() {
            findClassesStudentList();
        });
        fnInit();
    };

    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                searchActive: false,
                pageParam: pageParam,
                keyword: '',
                chartList: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '未分组'],
                pageData: {},
                resultData: {}
            },
            watch: {
                keyword: function () {
                    var temp = {};
                    var pageData = this.pageData;
                    var chartList = this.chartList;
                    for (var i = 0; i < chartList.length; i++) {
                        var item = chartList[i], tem = [];
                        for (var j = 0; j < pageData[item].length; j++) {
                            var stu = pageData[item][j];
                            if (stu.name.indexOf(this.keyword) !== -1) {
                                tem.push(stu);
                            }
                        }
                        temp[item] = tem;
                    }
                    vm.resultData = temp;
                },
                searchActive: function() {
                    var el = document.getElementById('search-input');
                    if(this.searchActive) {
                        setTimeout(function() {
                            el.focus();
                        },200)
                    }
                }
            }
        });
        initSortPage();
        findClassesStudentList();
    }

    // 获取页面数据
    function findClassesStudentList() {
        var url = 'clsClass/findClassesStudentList';
        var params = {
            'id': pageParam.id
        };
        var callback = function (data) {
            vm.pageData = data;
            vm.resultData = data;
            vm.chartList = deepCopy(vm.chartList);
        };
        POST(url, params, callback);
    }


    function handleItem(item) {
        if (USER.Get('memberType', true) == '2' || USER.Get('custId', true) == item.id) {
            fnOpenPublicWin('学生资料', 'class/student_info', {
                item: item,
                classId: pageParam.id
            });
        }
    }
</script>

</html>